//
//  SelectTheIdentityViewController.m
//  kqpai
//
//  Created by 辰领科技 on 16/6/24.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ChoosePageViewController.h"
#import "ChoosePageTableViewCell.h"

static NSString *cellIdentifier = @"ChoosePageTableViewCell";


@interface ChoosePageViewController ()
<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,assign)NSInteger count;
@property (strong, nonatomic) NSArray *titleArray;

@end

@implementation ChoosePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleArray = @[@"工程公司",@"设计师",@"建材零售商"];

    [self initViewLayout];
}

- (void)initViewLayout {
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];

    
   self.view.backgroundColor = [UIColor colorWithWhite:0.957 alpha:1.000];
    
    [self.tableView registerNib:[UINib nibWithNibName:cellIdentifier bundle:nil] forCellReuseIdentifier:cellIdentifier];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}


#pragma mark - 返回
- (IBAction)back:(id)sender {

  
    self.bock(@"");
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

//定义 UITableView cell 的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}

//定义 UITableView cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 47*VerticalRatio();
}

//定义 UITableView cell 展示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ChoosePageTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell= [[ChoosePageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    cell.image.hidden = YES;
    if (_count == indexPath.row) {
        cell.image.hidden = NO;
    }
    
    cell.titleLabel.text = self.titleArray[indexPath.row];
    
    return cell;
}

//定义 UITableView cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    _count = indexPath.row;
    [tableView reloadData];
    self.bock(self.titleArray[_count]);
    [self dismissViewControllerAnimated:YES completion:nil];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
